<?php

namespace PHPSpring\Annotation\Impl;

class ResponseJson {

  public static function response ($annoArgs, $ret, $exception, $target, $method, $args) {
    $format = '\\PHPSpring\\Type\\ResponseFormat';
    $success = 0;
    if (!empty($annoArgs)) {
      if (is_numeric($annoArgs[0])) {
        $success = $annoArgs[0];
      } else {
        $format = $annoArgs[0];
        if (isset($annoArgs[1])) {
          $success = $annoArgs[1];
        }
      }
    }
    if (!empty($exception)) {
      return [
        $format::CODE_NAME    => $exception->getCode(),
        $format::MESSAGE_NAME => $exception->getMessage(),
        $format::DATA_NAME    => $exception->getData()
      ];
    } else {
      return [
        $format::CODE_NAME => $success,
        $format::DATA_NAME => $ret
      ];
    }
  }

}
